package com.lovo.studentmanagement;


/**
 * 超级数组
 */
public class SuperArray {

    private Object [] objs = new Object[]{
            new Student("张三", 18, "男"),
            new Student("李四", 19, "男"),
            new Student("王五", 20, "女"),
    };

    /**
     * 根据下标获取元素
     * @param index
     * @return
     */
    public Object get(int index){
        return objs[index];
    }

    /**
     * 获取数组长度
     * @return
     */
    public int size(){
        return objs.length;
    }


    /**
     * 在数组末尾添加元素
     * @param value
     */
    public void add(Object value){

        Object[] newAry = new Object[objs.length + 1];
        for (int i = 0; i < objs.length; i++){
            newAry[i] = objs[i];
        }
        newAry[newAry.length-1] = value;
        objs = newAry;


    }

    /**
     * 根据下标删除元素
     * @param index
     */
    public void remove(int index){

        Object[] newAry = new Object[objs.length - 1];
        for (int i = 0; i < newAry.length; i++){
            if (i >= index){
                newAry[i] = objs[i + 1];
            }else {
                newAry[i] = objs[i];
            }

        }
        objs = newAry;
    }


    public void setObjs(Object[] objs) {
        this.objs = objs;
    }
}
